﻿using System.Collections.Generic;
using System.Linq;
using AmiCheckin.Lib;

namespace AmiCheckin.Code.Util
{
    public class CheckinEnableUtil
    {
        public static List<(string key, CheckinSet set)> GetSets(string msg, long group)
        {
            var cfg = AmiCheckin.Config;
            if (cfg.IsGroupEnable(group) is false)
                return new();

            List<(string key, CheckinSet set)> list;

            //先寻找群允许的所有Sets
            //没有设置的+设置了匹配的
            list = cfg.CheckinSets.Where(x => x.Value.SpecialGroups.Contains(group) || x.Value.SpecialGroups.Count == 0)
                .Select(x => (x.Key, x.Value)).ToList();

            //先寻找关键词
            if (msg == cfg.DefaultKeyword)
            {
                //默认关键词

                //寻找没有填写关键词的set和填了关键词的set

                list = list.Where(x => x.set.Keywords.Count == 0 || x.set.Keywords.Contains(msg))
                    .ToList();
            }
            else
            {
                //寻找对应
                list = list.Where(x => x.set.Keywords.Contains(msg))
                    .ToList();
            }


            return list;
        }
    }
}